<?php
/**
 * Nweb Framework
 *
 * This script is protected by copyright. It's use, copying, modification
 * and distribution without written consent of the author is prohibited.
 *
 * @category    source
 * @package     pl.nweb.framework.http
 * @author      Krzysztof Kardasz <krzysztof.kardasz@gmail.com>
 * @copyright   Copyright (c) 2011 Krzysztof Kardasz
 * @license     http://www.gnu.org/licenses/lgpl-3.0.txt  GNU Lesser General Public
 * @version     3.0 $Id: request.php 452 2011-12-07 12:04:19Z krzysztof.kardasz $
 * @link        http://code.google.com/p/nweb-framework/
 * @link        http://framework.nweb.pl
 */

namespace pl\nweb\framework\http;

/**
 * Żądanie HTTP
 *
 * @category    source
 * @package     pl.nweb.framework.http
 * @author      Krzysztof Kardasz <krzysztof.kardasz@gmail.com>
 * @copyright   Copyright (c) 2011 Krzysztof Kardasz
 * @version     3.0 $Id: request.php 452 2011-12-07 12:04:19Z krzysztof.kardasz $
 */
class Request
{
    /**
     * Wersja protokołu HTTP
     *
     * @var string
     */
    private $_httpVersion = null;

    /**
     * Metoda HTTP
     *
     * @var string
     */
    private $_httpMethod = null;

    /**
     * Uri żądania
     *
     * @var string
     */
    private $_httpUri = null;

    /**
     * Nagłówki
     *
     * @var array
     */
    private $_headers = array();

    /**
     * Treść
     *
     * @var string
     */
    private $_body = null;


    /**
     * Zwraca kod odpowiedzi
     *
     * @param  string $method metoda
     * @param  string $uri uri
     * @param  string $http wersja http
     * @param  array $headers nagłówki
     * @param  string $body treść
     * @return void
     */
    public function __construct ($method, $uri, $http, $headers, $body)
    {
        $this->_httpMethod  = $method;
        $this->_httpUri     = $uri;
        $this->_httpVersion = $http;
        $this->_headers     = $headers;
        $this->_body        = $body;
    }

    /**
     * Zwraca wersję protokołu HTTP
     *
     * @return string
     */
    public function getHttpVersion()
    {
        return $this->_httpVersion;
    }

    /**
     * Zwraca metodę żądania HTTP
     *
     * @return string
     */
    public function getHttpMethod()
    {
        return $this->_httpMethod;
    }

    /**
     * Zwraca URI żądania HTTP
     *
     * @return string
     */
    public function getHttpUri()
    {
        return $this->_httpUri;
    }

    /**
     * Zwraca nagłówek
     *
     * @param  string $name nazwa nagłówka
     * @return array|string|null
     */
    public function getHeader($name)
    {
        if(isset($this->_headers[$name])) {
            return $this->_headers[$name];
        }
        return null;
    }

    /**
     * Zwraca nagłówki
     *
     * @return array
     */
    public function getHeaders()
    {
        return $this->_headers;
    }

    /**
     * Zwraca treść
     *
     * @return string
     */
    public function getBody()
    {
        return $this->_body;
    }
}